package com.songlanyun.modules.marketing.groupbuy.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.enums.MarketingConstant;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;

/**
 * 拼团活动
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-27 14:03:39
 */
@Data
@TableName("yxt_marketing_group_buy_activity")
public class GroupBuyActivity extends RootEntity<Long, GroupBuyActivity> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 商家店铺id
     */
    private Long shopId;
    /**
     * 拼团活动名称
     */
    private String name;
    /**
     * 活动开始时间
     */
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date startTime;
    /**
     * 活动结束时间
     */
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date endTime;
    /**
     * 订单自动关闭时间（商品按下单减库存，请设置未付款订单自动取消时间及时释放库存，可输入3-360分钟）
     */
    private Integer closeTime;
    /**
     * 活动图片
     */
    private String imgUrl;
    /**
     * 成团小时数(开团之后，多长时间关团的小时数)
     */
    private Integer limitHour;
    /**
     * 是否废弃
     */
    @TableField("`discard`")
    private Boolean discard;
    /**
     * 活动说明
     */
    @TableField("`explain`")
    private String explain;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @TableField(exist = false)
    private Integer goodsNum;

    @Override
    public Long getIdentity() {
        return id;
    }

    /**
     * 活动状态
     */
    @TableField(exist = false)
    private MarketingConstant.ActiveState activeState;

    /**
     * 活动状态
     *
     * @return
     */
    public MarketingConstant.ActiveState getActiveState() {
        return MarketingConstant.getGroupBuyActiveState(this.startTime, this.endTime);
    }

    @JsonIgnore
    public Long getPayExpireTime(Long current)
    {
        return this.getCloseTime()*60*1000 +current;
    }


}
